package com.ssh.service;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import jdwl.hrmgrsys.pojo.Staff;

import org.springframework.stereotype.Service;

import com.ssh.core.QueryResult;
import com.ssh.dao.CommonDao;

@Service("CRUDService")
public abstract class CRUDService<T> {
	/**
	 * CommonDao通过反射机制，在调用时，自动获取了当前对象的类型
	 */
	@Resource(name="commonDao")
	protected CommonDao<T> dao;
	
	public CommonDao<T> getDao() {
		return dao;
	}

	public void setDao(CommonDao<T> dao) {
		this.dao = dao;
	}

	public T save(T obj){
		dao.save(obj);
		return obj;
	}
	
	public void update(T obj){
		dao.update(obj);
	}
	
	public void delete(T obj){
		dao.delete(obj);
	}
	public Object get(Class entityClass ,Serializable id){
		return dao.findById(entityClass,id);
	}
	
	public QueryResult list(Class entity,int pageNo,int pageSize,List<String> whereClause, LinkedHashMap<String, String> orderbyClause) {
		return dao.findScrollData(entity,pageNo, pageSize,whereClause,orderbyClause);
	}
}
